/**
 * Created by Administrator on 2016/12/3.
 */

$(function () {

    var swiper_wrapper = document.querySelector(".swiper-wrapper"),
        menu_ul = document.querySelector(".menu_ul"),
        freeLine_ul = document.querySelector(".freeLine_ul"),
        freeLine_img_ul = document.querySelector(".freeLine_img_ul"),
        city_play_ul = document.querySelector("city_play_ul")
    ;

     //搜索框
    $(".seach").focus(function () {
        $(".menu1 ul").css("display","block")
    }).blur(function () {
        $(".menu1 ul").css("display","none")
    } )
    $(".menu1 ul li").mouseenter(function () {
        $(this).css("background","#61d482")
    }).mouseleave(function () {
        $(this).css("background","")
    })

    // 轮播图数据
    $.get("../banner.json", function(data){
        // console.log(data)
        $.each(data, function(m,n){
            // console.log(n)
            $("<div/>").addClass("swiper-slide").append(
                    $("<a/>").attr("href", n.href).append(
                            $("<img/>").attr("src", n.imgUrl)
                        )
            ).appendTo(swiper_wrapper)
        })
        //轮播图
        var mySwiper = new Swiper('.swiper-container', {
            speed : 1000,
            loop : true,
            paginationClickable :true,
            prevButton:'.swiper-button-prev',
            nextButton:'.swiper-button-next',
            pagination : '.swiper-pagination',
            autoplayDisableOnInteraction : false,
            autoplay: 2000//可选选项，自动滑动
        })
        document.querySelector(".swiper-container").onmouseover = function(){
            mySwiper.stopAutoplay();
        }
        document.querySelector(".swiper-container").onmouseout = function(){
            mySwiper.startAutoplay();
        }
    })
   
    // 二级菜单
    $.get("../menu.json" , function(res){
        for( var j = 0; j <res.length; j++){
            // console.log(res[j].mainCity)
            $("<li/>").append(
                    $("<h4/>").html(res[j].title)
            ).append(
                    $("<a/>").html(res[j].mainCity)
            ).appendTo(menu_ul)
        }
    })
    
    // 机酒自由行数据
    $.get("../freeWalk.json", function(res){
       for (var i = 0; i < res.length; i++) {
            $("<li/>").append(
                $("<a/>").html(res[i].title)
            ).appendTo(freeLine_ul)
       };
    })
    //机酒自由行
    $.get("../freeWalk.json", function (res) {
        $.each(res, function (m,n) {
            //console.log(res)
            //console.log(res[m]);
            //console.log(res[1].data[0].imgUrl)
            $.each(res, function (m,n) {
                //遍历每一个li，便于创建其下面显示的div
                $(".freeLine .title ul li").hover(function () {
                    // console.log($(".jijiubox ul li").find(".time"))
                    $.each(res[$(this).index()].data,function (m,n) {
                        $(".freeLine_img ul li").find(".tittle").eq(m).html(n.title);
                        $(".freeLine_img ul li").find(".pprice").eq(m).html(n.price);
                        $(".freeLine_img ul li").find("img").eq(m).attr("src", n.imgUrl);
                    })
                })
            })
        })
    })

    $("footer").load("views/footer.html");




})